<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        document.addEventListener('DOMContentLoaded', function(){
            console.log('test DOMContentLoaded')
        })
    </script>
    <style>
        @keyframes run {
            from {
                transform: translateX(0px);
            }

            to {
                transform: translateX(300px);
            }
        }

        .ani {
            width: 50px;
            height: 50px;
            border-radius: 25px;
            background: red;
            animation: run 500ms linear infinite alternate;
        }

        .btn-list {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: row;
        }

        .btn {
            width: 100px;
            height: 100px;
            background: pink;
            color: white;
            border-radius: 50%;
            font-size: 18px;
            display: flex;
            justify-content: center;
            align-items: center;
            justify-self: center;
        }

        .item {
            width: 100%;
            height: 80px;
            color: white;
            font-size: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'ZCOOLQingKeHuangYou';
        }

        .item-red {
            background: red;
        }

        .item-blue {
            background: blue;
            margin-top: 10px;
        }

       
    </style>
</head>

<body>
    <!-- <div class="ani"></div> -->
    <div class="btn-list">
        <div id="normal" class="btn">normal</div>
        <div id="optimize" class="btn">optimize</div>
    </div>
    <div id="app"> </div>
    <div class="item item-blue"> 1</div>
    <div class="item item-red"> 2</div>

    <div class="item item-blue"> 3</div>
    <div class="item item-red"> 4</div>

    <div class="item item-blue"> 5</div>
    <div class="item item-red"> 6</div>

    <div class="item item-blue"> 7</div>
    <div class="item item-red"> 8</div>

    <div class="item item-blue"> 9</div>
    <div class="item item-red"> 10</div>

    <div class="item item-blue"> 11</div>
    <div class="item item-red"> 12</div>

    <div class="item item-blue"> 13</div>
    <div class="item item-red"> 14</div>

    <div class="item item-blue"> 15</div>
    <div class="item item-red"> 16</div>
    
    <script type="module">
        import { DynamicTasks } from "/run-time-opti/dist/es/index.js"
        let count = 5;
        let curCount = 0;
        const test = () => {
            const app = document.getElementById("app")
            let str = ''
            for (let i = 0; i < 10000; i++) {
                str += i
            }
            if (curCount < count) {
                curCount++;
                test();
            }
            // console.log('test str', str)
        }
        const p = (res) => {
            curCount = 0;
            test()
            console.log("test p1 res", res, 1111);
            return 1111;
        };


        const list = []
        for (let i = 0; i <1500;i++) {
            list[i] = {
                key: `p${i}`,
                task: p
            };
        }

        const onClick = (frame = false) => {
            const task = new DynamicTasks({ parallelMax: 1, frame });
            task.start(list).then(data => {
                console.log('test data done:', data);
            });

            // task.start([{
            //     key: "p4",
            //     task: p4,
            //     parallel: true,
            // },
            // {
            //     key: "p5",
            //     task: p5,
            //     parallel: true,
            // },
            // {
            //     key: "p6",
            //     task: p6,
            //     parallel: true,
            // }]).then(data => {
            //     console.log('test data 222', data);
            // });
        }
        const normal = document.getElementById("normal")
        normal.addEventListener('click', () => onClick())

        const optimize = document.getElementById("optimize")
        optimize.addEventListener('click', () => onClick(true))
    </script>
</body>

</html>